Skip to content

Conversation

@shannoncai
Copy link

@shannoncai shannoncai commented Dec 7, 2024

Handles #12417

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Dec 7, 2024
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @shannoncai! Please take a look at the comments.

got = self._remove_unwanted_precision(want, got)

if "..." in want:
want_regex = re.escape(want).replace(r"\.\.\.", ".*")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit simplistic in the sense that it will replace any ... found in the docstring, even if they are used in places where we don't want this replacement to happen, say inside a string literal.

Perhaps we can limit our replacement to lines containing a single ... (minus spaces)?

Here is how the stdlib does this: https://github.com/python/cpython/blob/1503fc8f88d4903e61f76a78a30bcd581b0ee0cd/Lib/doctest.py#L295-L342

I'm OK with copying that code over pytest.

Comment on lines +654 to +655
print(f"Transformed WANT: {want_regex}") # Debugging output
print(f"GOT: {got}") # Debugging output
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like those are left-overs.

Suggested change
print(f"Transformed WANT: {want_regex}") # Debugging output
print(f"GOT: {got}") # Debugging output

assert _is_main_py(dunder_main) == expected


def test_doctest_wildcard(pytester):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_doctest_wildcard(pytester):
def test_doctest_wildcard(pytester: Pytester) -> None:

# Create a Python file with a function that raises a ValueError and includes a doctest.
pytester.makepyfile(
"""
def _test_doctest_wildcard():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _test_doctest_wildcard():
def doctest_wildcard():

@@ -0,0 +1 @@
Fix handling of ellipsis (...) in traceback comparisons for doctests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fix handling of ellipsis (...) in traceback comparisons for doctests
Fix handling of ellipsis (``...``) in traceback comparisons for doctests.

@nicoddemus
Copy link
Member

Closing as this has not seen activity in awhile.

Feel free to reopen if you want to work on this again.

@nicoddemus nicoddemus closed this Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants